
// Definition for a binary tree node.
function TreeNode(val, left, right) {
    this.val = (val===undefined ? 0 : val)
    this.left = (left===undefined ? null : left)
    this.right = (right===undefined ? null : right)
}

/**
 * @param {TreeNode} root
 * @return {number}
 */
var getMinimumDifference = function(root) {
  let result = [];
  function preView(node) {
    if(!node) return;
    result.push(node.val);
    preView(node.left);
    preView(node.right);
  }
  preView(root);
  result.sort((a, b) => b - a);
  let min = 2 ** 16;
  for(let i = 0; i < result.length - 1; i++) {
    if(min > result[i] - result[i + 1]) min = result[i] - result[i + 1];
  }
  return min;
};
